package com.svmc.app.task.tabmanager;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.svmc.app.task.activity.R;
import com.svmc.app.task.activity.SettingActivity;

public class TabMain extends TabActivity {
	//--------------------------------//
	private static TabMain theInstance;

    public static TabMain getInstance() {
        return TabMain.theInstance;
    }

    public TabMain() {
    	TabMain.theInstance = this;
    }
    //-------------------------------//
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.tab_main);
		
		setTabs();

	}

	private void setTabs() {
		addTab("Home", R.drawable.tab_home, GroupHomeActivity.class);
		addTab("Setting", R.drawable.tab_setting, SettingActivity.class);
		addTab("Help", R.drawable.tab_help, GroupHelpActivity.class);
		// addTab("Search", R.drawable.tab_search, OptionsActivity.class);
	}

	private void addTab(String labelId, int drawableId, Class<?> c) {
		TabHost tabHost = getTabHost();
		Intent intent = new Intent(this, c);
		TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);

		View tabIndicator = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator, getTabWidget(), false);
		TextView title = (TextView) tabIndicator.findViewById(R.id.title);
		title.setText(labelId);
		ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
		icon.setImageResource(drawableId);
		icon.getLayoutParams().height = 28;
		icon.getLayoutParams().width = 28;
		spec.setIndicator(tabIndicator);
		spec.setContent(intent);
		tabHost.addTab(spec);
	}

	
}
